package org.csu.zhangdian.service;

import org.csu.zhangdian.domain.Account;
import org.csu.zhangdian.persistence.AccountMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AccountService {

    @Autowired
    private AccountMapper accountMapper;

    public Account getAccount(String username, String password){
        Account account = new Account();
        account.setUsername(username);
        account.setPassword(password);
        return  accountMapper.getAccountByUsernameAndPassword(account);
    }

    public Account getAccount(String username){
        return accountMapper.getAccountByUsername(username);
    }


    public void updatePassword(Account account){
        if(account.getPassword() != null && account.getPassword().length() > 0){
            accountMapper.updatePassword(account);
        }
    }
}
